package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.common.entity.PageDTO;
import com.boss.common.util.PageUtils;
import com.boss.framework.dto.PaginationDTO;

import com.boss.salary.entity.PersonSalaryExt;
import com.boss.salary.service.IPersonSalaryExtService;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

@RestSchema(schemaId = "personSalaryExtController")
@RestController
@RequestMapping(value = "/personSalaryExtController", produces = MediaType.APPLICATION_JSON)
public class PersonSalaryExtController extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(PersonSalaryExtController.class);


    @Autowired
    private IPersonSalaryExtService service;

    /**
     * 查询 人员工资扩展数据分页
     * @param offset
     * @param limit
     * @return
     */
    @GetMapping("/queryPersonSalaryExtPage")
    public ApiResultDTO queryPersonSalaryExtPage(@RequestParam(value = "offset") String offset,
                                                  @RequestParam(value = "limit") String limit) {
        try {
            Map<String, Object> parameters = new HashMap<>(8);
            parameters.put("offset", offset);
            parameters.put("limit", limit);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTO(parameters);
            PageDTO<PersonSalaryExt> pageDTO = service.queryPersonSalaryExtPage(paginationDTO);
            return ApiResultDTO.success(pageDTO,null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询失败！");
        }
    }

    /**
     * 新增 人员工资扩展数据
     * @param PersonSalaryExt
     * @return
     */
    @PostMapping("/savePersonSalaryExt")
    public ApiResultDTO savePersonSalaryExt(@RequestBody PersonSalaryExt PersonSalaryExt) {
        try {
            service.savePersonSalaryExt(PersonSalaryExt);
            return ApiResultDTO.success(null, "保存成功");
        } catch (Exception e) {
            logger.error("新增 人员工资扩展数据发生异常", e);
            return ApiResultDTO.error(ERROR_RSCODE, "保存失败！");
        }
    }

    /**
     * 更新 人员工资扩展数据
     * @param PersonSalaryExt
     * @return
     */
    @PostMapping("/updatePersonSalaryExt")
    public ApiResultDTO updatePersonSalaryExt(@RequestBody PersonSalaryExt PersonSalaryExt) {
        try {
            service.updatePersonSalaryExt(PersonSalaryExt);
            return ApiResultDTO.success(null, "更新成功");
        } catch (Exception e) {
            logger.error("更新 人员工资扩展数据发生异常", e);
            return ApiResultDTO.error(ERROR_RSCODE, "更新失败");
        }
    }

    /**
     * 删除 人员工资扩展数据
     * @param id
     * @return
     */
    @DeleteMapping("/deletePersonSalaryExt/{id}")
    public ApiResultDTO deletePersonSalaryExt(@PathVariable("id") String id) {
        try {
            service.deletePersonSalaryExt(id);
            return ApiResultDTO.success(null, "删除成功");
        } catch (Exception e) {
            logger.error("删除 人员工资扩展数据发生异常", e);
            return ApiResultDTO.error(ERROR_RSCODE, "删除失败");
        }
    }

}
